<?php

/**
 * Description of PageController
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
final class PageController extends ControlPage {

    /**
     * The constructor.
     */
    public function __construct() {
        parent::__construct();
        
        /**
         * Page parameters. 
         */
        $this->pseudoFile = PageModel::getCurrentPagePseudoFile();
        $this->urlIdentifier = PageModel::getCurrentPageUrlIdentifier();
        $this->articleId = PageModel::getCurrentPageArticleId();
        $this->pageNumber = PageModel::getCurrentPageNumber();
        $this->page = PageModel::getCurrentPage();
        
        /**
         * Page display: running the method 'run' in ControlPage. 
         */
        $this->rendered = $this->run();
    }
    
    /**
     * Getting the page-specific view fields from the model.
     * 
     * @return array 
     */
    protected function getViewFields() {
        $output = array();
        return $output;
    }
    
    /**
     * Form submission.
     * 
     * @param string $action
     * @return bool
     */
    protected function process($action = NULL) {
        switch ($action) {
            case 'login':
                static::pageRedirect('about');
                break;
            case 'registration':
                static::pageRedirect();
                break;
                
        }
        return FALSE;
    }
    
    /**
     * Generating the view object.
     * 
     * @param string $pseudoFile
     * @param array $viewFields
     * @return mixed
     */
    protected function genView($pseudoFile, $viewFields = array()) {
        switch ($pseudoFile) {
            case HTML_FILENAME:
                return new PageView($viewFields);
            case XML_PAGE_FILENAME:
                return new XmlDataView($viewFields);
            case CSS_FILENAME:
                return new StylesheetView($viewFields);
            case JAVASCRIPT_FILENAME:
                return new JavaScriptView($viewFields);
            case FEED_FILENAME:
                return new RssFeedView($viewFields);
            case XML_DATA_FILENAME:
                return new XmlDataView($viewFields);
            case XSL_FILENAME:
                return new XslView($viewFields);
            case AJAX_FILENAME:
                return new AjaxView($viewFields);
        }        
    }

}